const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

let newArr = [];
for (let i = 0; i < arr.length;) {
  newArr.push(arr.slice(i, i += 5))
}
// console.log(newArr);
// console.log(newArr.flat());


let pinArr = []
function pin(arr) {
  for (let item of arr) {
    console.log(item);
    if (Array.isArray(item)) {
      pin(item)
    } else {
      pinArr.push(item)
    }
  }
  return pinArr
}
// pin(newArr)



function pinV2(A) {
  const res = []
  for (let item of A) {
    if(Array.isArray(item)){
      pinV2(item)
    }else {
      res.push(item)
    }
  }
  return res
}

console.log(pinV2(newArr));


// 将数组拆分成每组spilter个的二维数组
function splitC(arr, spilter){
  if(spilter > arr.length) return arr

  const res = []
  for (let i = 0; i < arr.length;) {
    res.push(arr.slice(i,i +=spilter))
  }
  return  res
}

console.log(splitC(arr, 10));

